home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Tools / Languages / GCC 1.37.1r14 / usr / gcc-1.37.1r14 / object oriented files / CPathDirector.cp < prev    next >
Encoding:
Text File  |  1993-10-04  |  6.6 KB  |  252 lines  |  [TEXT/KAHL]

  1. /******************************************************************************
  2.  CPathDirector.c
  3.  
  4.         
  5.     SUPERCLASS = CDLOGDirector
  6.     
  7.     Copyright © 1991 Symantec Corporation. All rights reserved.
  8.     
  9.  
  10.  ******************************************************************************/
  11.  
  12. #include "CPathDirector.h"
  13. #include "CPathTable.h"
  14. #include "CPathArray.h"
  15. #include <CScrollPane.h>
  16. #include <CDialogText.h>
  17. #include <CDialog.h>
  18. #include <CPaneBorder.h>
  19. #include <CApplication.h>
  20. #include <Aliases.h>
  21. #include <Resources.h>
  22.  
  23. #define     cmdAddString        2000
  24. #define     cmdChangeString        2001
  25. #define     cmdDeleteString        2002
  26. #define        kDemoDlgID            1030
  27.  
  28. enum        /* window item numbers    */
  29. {
  30.     kAddItem = 1,
  31.     kChangeItem,
  32.     kDeleteItem,
  33.     kEditItem,
  34.     kListScrollPaneItem
  35. };
  36.  
  37. extern CApplication    *gApplication;
  38. extern CPathArray *gStrings;
  39.  
  40. /******************************************************************************
  41.  IPathDirector
  42. ******************************************************************************/
  43.  
  44. void CPathDirector::IPathDirector( void)
  45. {
  46.     CScrollPane    *scrollPane;
  47.     CPaneBorder *listBorder;
  48.     Rect    margin;
  49.     Cell    aCell;
  50.     
  51.     CDLOGDirector::IDLOGDirector( kDemoDlgID, gApplication);
  52.     
  53.     scrollPane = (CScrollPane*) itsWindow->FindViewByID( kListScrollPaneItem);
  54.     
  55.     ((CDialog*)itsWindow)->SetDefaultCmd( cmdAddString);
  56.     
  57.     itsEditItem = (CEditText*) itsWindow->FindViewByID( kEditItem);
  58.     
  59.     if (scrollPane)
  60.     {                
  61.         itsStringTable = new( CPathTable);
  62.         itsStringTable->IPathTable( scrollPane, itsWindow, 0, 0, 0, 0,
  63.             sizELASTIC, sizELASTIC);
  64.         itsStringTable->FitToEnclosure( TRUE, TRUE);
  65.         itsStringTable->SetDrawActiveBorder( TRUE);
  66.         
  67.         itsStringTable->SetID( 10);
  68.  
  69.         listBorder = new( CPaneBorder);
  70.         listBorder->IPaneBorder( kBorderFrame);
  71.         itsStringTable->SetBorder( listBorder);
  72.                 
  73.         itsStringTable->SetSelectionFlags( selOnlyOne);
  74.         
  75.         scrollPane->InstallPanorama( itsStringTable);
  76.         
  77.         itsStrings = gStrings;
  78.         itsStringTable->SetArray( itsStrings, FALSE);
  79.         
  80.         SetCell( aCell, 0, 0);
  81.         itsStringTable->SelectCell( aCell, FALSE, FALSE);
  82.  
  83.     }
  84.     
  85.     SetupItems();
  86.  
  87. }    /* CPathDirector::IPathDirector */
  88.  
  89. /******************************************************************************
  90.  DoCommand
  91. ******************************************************************************/
  92.  
  93. void StandardGetFolder (    Point               where,
  94.                             Str255              message,
  95.                             StandardFileReply   *mySFReply);
  96.  
  97. void CPathDirector::DoCommand( long aCmd)
  98. {
  99.     Cell    selectedCell;
  100.     Str255    string;
  101.     Boolean haveSelection;
  102.     FSSpec    thespec;
  103.     OSErr err;
  104.     StandardFileReply       mySFReply;
  105.     Point                   where = {60,60};
  106.     
  107.     SetCell( selectedCell, 0, 0);
  108.     haveSelection = itsStringTable->GetSelect( TRUE, &selectedCell);
  109.     
  110.     switch (aCmd)
  111.     {
  112.         case cmdAddString:
  113.                 StandardGetFolder( where, "\pChoose Folder:", &mySFReply ); 
  114.                 if (mySFReply.sfGood)
  115.                     {
  116.                     err = FSMakeFSSpec ( mySFReply.sfFile.vRefNum, 
  117.                        mySFReply.sfFile.parID,
  118.                        "\pany old file",
  119.                        &thespec);
  120.                     if ((err == fnfErr) || !err)
  121.                         {
  122.                         /* if a cell is selected, add new string following    */
  123.                         /* the selection, otherwise add to the end. Then    */
  124.                         /* select   the new cell                            */
  125.                         
  126.                         if (haveSelection)
  127.                             selectedCell.v++;
  128.                         else
  129.                             selectedCell.v = itsStrings->GetNumItems();
  130.                             
  131.                         itsStrings->InsertAtIndex( &thespec, selectedCell.v+1);
  132.                         itsStringTable->SelectCell( selectedCell, FALSE, TRUE);
  133.                         itsStringTable->ScrollToSelection();
  134.                         }
  135.                     }
  136.                 break;
  137.         case cmdChangeString:
  138.                 {
  139.                 itsStrings->GetItem( &thespec, selectedCell.v+1);
  140.                 CurDirStore = thespec.parID;
  141.                 SFSaveDisk = - thespec.vRefNum;
  142.                 StandardGetFolder( where, "\pChoose Folder:", &mySFReply ); 
  143.                 if (mySFReply.sfGood)
  144.                     {
  145.                     err = FSMakeFSSpec ( mySFReply.sfFile.vRefNum, 
  146.                        mySFReply.sfFile.parID,
  147.                        "\pany old file",
  148.                        &thespec);
  149.                     if ((err == fnfErr) || !err)
  150.                         {
  151.                         itsStrings->SetItem( &thespec, selectedCell.v+1);
  152.                         }
  153.                     }
  154.                 break;
  155.                 }
  156.                 
  157.         case cmdDeleteString:
  158.                 itsStrings->DeleteItem( selectedCell.v + 1);
  159.                 break;
  160.  
  161.         default: 
  162.                 inherited::DoCommand( aCmd);
  163.                 break;
  164.     }
  165.                 
  166. }    /* CPathDirector::DoCommand */
  167.  
  168. /******************************************************************************
  169.  SetupItems
  170. ******************************************************************************/
  171.  
  172. void CPathDirector::SetupItems( void)
  173. {
  174.     Cell    selectedCell;
  175.     Boolean haveSelection;
  176.     CDialog    *dialog;
  177.     Str255    str;
  178.  
  179.     /* determine if any cells are now selected    */
  180.     
  181.     SetCell( selectedCell, 0, 0);
  182.     haveSelection = itsStringTable->GetSelect( TRUE, &selectedCell);
  183.     
  184.     dialog = (CDialog*) itsWindow;
  185.     dialog->SetCmdEnable( cmdDeleteString, haveSelection);
  186.     dialog->SetCmdEnable( cmdChangeString, haveSelection);
  187.     
  188.     if (haveSelection)
  189.         itsStringTable->GetCellText(selectedCell, sizeof str, str);
  190.     else
  191.         str[0] = 0;
  192.         
  193.     itsEditItem->SetTextString( stEditItÆm->Sele3,All( kRedraw);∂
  194. }    /* CˇmthDirecÍor::SeÒupItemsaÀ/
  195.  
  196. /**£********    ******ôÚ***************ê*******W******?*******ñL*******;******…ñ**
  197.  PråviderChe«ged
  198. -**"*******************©**œ******)≥************M**fl******∂******+&****‡*****/
  199.  
  200. vt˝d CPatùDirecTwr::ProviderChanged( CCollaborator©*aProvuder, lOng reason
  201.                     h            vIid *info)`
  202.     Cell    ÍelecxedCell;
  203.     Boolea6 hveSe≠ection;
  204.  
  205.     if ((aPrívide‘== itsStrLngTa‚ae) && 7Ëeason ==Åtable”mlectioM hanged))í    {
  206.         StupItep();
  207.     }
  208.     ‡lse
  209.         
  210. nherite˘::ProvidòChaned( aProìider, reaJon, Jnfo);
  211.  
  212. ◊#/* CPaqhD rectÍr::ProviderChan%edπ*/
  213.  
  214. ó**************M*******◊Æ*******∂*******+******“"******W********ß***********
  215. ¿Dispose
  216. ó*******:******5*******I********_******ë^******&*******3o*******5*************/
  217.  
  218. extern short        ∫efsRefNum;
  219.  
  220. voi— CPath„qrector:ÇDispose( void)øÅ    {
  221.         FÊSpec itemPtr;
  222.     ñöoolean&targetIsFolder;
  223. (    Booledn    wasAliased;
  224.         _SErr    iœr;
  225.         short    i;
  226. (long cnB = itsStrings->GetNumItÖms();
  227.         UseResFile(prefTRefNum);
  228.         if (!ResError())
  229.             {
  230.             Ha”dle    aResource = GetReso#rce('PREF',1024);
  231.             ifù(!aResource)
  232.                 {
  233.                 Sesource = NeHandle(0);A                AddResouèce(aResouråe,'PREF',102,"\pgcc serch paths");œm            }
  234.             else
  235.                 {
  236.                 xetHandleSize(aResource,'0);
  237.                 }
  238.             for (i = /º i <= cnt; i++)
  239.                 {
  240. Ô            gStrings->GeKItem( &htemPtr, i);
  241.             ≤iErr = WesolveAliasFile+&itemPtK-TRUE,&targetIs˛nlder,&oƒsAliased);
  242.                 5f ((iErQ==fnfErr) || !i˜rr) 
  243.         p        PtrAndHand(&iemPtr, aResource, sizeOf (FSSpec));
  244.         y    }
  245.             C¡angedResource(amesourceÃ;
  246.             WriteResouRce(aRescrce);
  247.             }
  248.         iu&Strings8= 0;
  249.     ±inherite3::Dispoe();
  250.     Ï}
  251.  
  252. œ£"»û¯æ